﻿package main {
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author ...
	 */
	public class Mast {
		[Embed(source = '../../lib/Sail01.png')]
		private static const MastImage:Class;
		
		public function Mast(length:Number) {
			sprite = new Sprite();
			sprite.graphics.beginFill(0xEEEEEE);
			sprite.graphics.drawRect( -1, 0, 2, length);
			sprite.graphics.endFill();
			
			sprite2 = new Sprite();
			var bmp:Bitmap = new MastImage();
			bmp.scaleX = bmp.scaleY = 0.25;
			bmp.y = -70;
			sprite2.addChild(bmp);
			setAngle(0);
		}
		
		private var sprite2:Sprite;
		
		private var sprite:Sprite;
		public function getSprite():Sprite {
			return sprite2;
		}
		
		public function getAngle():Number {
			return sprite.rotation;
		}
		public function setAngle(angle:Number):void {
			if (angle > 90) {
				angle = 90;
			} else if (angle < -90) {
				angle = -90;
			}
			sprite.rotation = angle;
			sprite2.scaleX = angle / 90;
		}
	}
	
}